using System;
using System.Linq;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.Data.Filtering;
using System.Collections.Generic;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Layout;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Templates;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Model.NodeGenerators;

namespace DomainComponents.XCRM.Controllers
{
    // For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
    public partial class QualifyLeadController : ViewController
    {
        PopupWindowShowAction qualifyLead;

        private void qualifyLead_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
        {
            //e.View = Application.CreateDetailView(Application.CreateObjectSpace(), QualifyLeadParameters.CreateQualifyLeadParameters());
            //((DetailView)e.View).ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;

        }

        private void qualifyLead_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
        {
            //((QualifyLeadParameters)e.PopupWindow.View.CurrentObject).Qualify(((ILead)View.CurrentObject), View.ObjectSpace);
            //View.ObjectSpace.CommitChanges();
            //if (View is ListView)
            //{
            //    View.ObjectSpace.Refresh();
            //}
        }

        public QualifyLeadController()
        {
            InitializeComponent();
            RegisterActions(components);
            // Target required Views (via the TargetXXX properties) and create their Actions.

            TargetObjectType = typeof(ILead);
            qualifyLead = new PopupWindowShowAction(this, "QualifyLead", PredefinedCategory.View);
            qualifyLead.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
            qualifyLead.Caption = "Qualify Lead...";
            qualifyLead.TargetObjectsCriteria = "Status = 'None'";
            qualifyLead.Execute += new PopupWindowShowActionExecuteEventHandler(qualifyLead_Execute);
            qualifyLead.CustomizePopupWindowParams += new CustomizePopupWindowParamsEventHandler(qualifyLead_CustomizePopupWindowParams);
        
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
        }
        protected override void OnDeactivated()
        {
            // Unsubscribe from previously subscribed events and release other references and resources.
            base.OnDeactivated();
        }
    }
}
